package com.csw.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
@RabbitListener(queues =TopicExchangeBindingQueue.YGZS_POST_INSERT_QUEUE_NAME ,containerFactory = "rabbitListenerContainerFactory")
public class TopicYgzsPostInsertReceiver {
    private Logger logger = LoggerFactory.getLogger(TopicYgzsPostInsertReceiver.class);

    @RabbitHandler
    public void process(@Payload SendEntity sendEntity, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
                        Channel channel) throws IOException {
        try {
            logger.info("新版员工之声ding通知【队列接收】" + JSON.toJSONString(sendEntity));
            sendEntity = null;
            //dosomething
            if (sendEntity== null) {
                channel.basicNack(deliveryTag,false,false);
                return;
            }
            //dosomething

            channel.basicAck(deliveryTag, false);
        } catch (IOException e) {
            logger.error("新版员工之声帖子插入失败：【{}】,【{}】",e.getMessage(),e.getStackTrace());
            channel.basicNack(deliveryTag,false,false);
        }

    }
}
